load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//:def.bzl", "DEFAULT_LANGUAGES", "gazelle_binary")

gazelle_binary(
    name = "gazelle",
    languages = DEFAULT_LANGUAGES,
    visibility = ["//visibility:public"],
)

go_library(
    name = "gazelle_lib",
    # keep
    srcs = [
        "diff.go",
        "fix.go",
        "fix-update.go",
        "main.go",
        "metaresolver.go",
        "print.go",
        "profiler.go",
        "update-repos.go",
    ],
    importpath = "github.com/bazelbuild/bazel-gazelle/cmd/gazelle",
    tags = ["manual"],
    visibility = ["//visibility:public"],
    deps = [
        "//config",
        "//flag",
        "//internal/wspace",
        "//label",
        "//language",
        "//language/bazel/visibility",
        "//language/go",
        "//language/proto",
        "//merger",
        "//repo",
        "//resolve",
        "//rule",
        "//walk",
        "@com_github_bazelbuild_buildtools//build",
        "@com_github_pmezard_go_difflib//difflib",
    ],
)

go_test(
    name = "gazelle_test",
    size = "small",
    srcs = [
        "diff_test.go",
        "fix_test.go",
        "integration_test.go",
        "langs.go",  # keep
        "profiler_test.go",
    ],
    data = [
        "@go_sdk//:ROOT",
        "@go_sdk//:files",
    ],
    embed = [":gazelle_lib"],
    x_defs = {"goRootFile": "$(rlocationpath @go_sdk//:ROOT)"},
    deps = [
        "//config",
        "//internal/wspace",
        "//testtools",
        "@com_github_google_go_cmp//cmp",
        "@io_bazel_rules_go//go/runfiles",
    ],
)

filegroup(
    name = "all_files",
    testonly = True,
    srcs = [
        "BUILD.bazel",
        "diff.go",
        "diff_test.go",
        "fix.go",
        "fix-update.go",
        "fix_test.go",
        "integration_test.go",
        "langs.go",
        "main.go",
        "metaresolver.go",
        "print.go",
        "profiler.go",
        "profiler_test.go",
        "update-repos.go",
    ],
    visibility = ["//visibility:public"],
)
